
	#include "MaxSonarDriver.h"
/******************************************************************************
*   					PUBLIC FUNCTIONS 
******************************************************************************/
#if MAXSONAR_FORMAT == UART_DIST
	//function to read distance,using UART port
#endif

#if MAXSONAR_FORMAT == ADC_DIST
/*****************************************************************************
 * Function:	VfnMaxSonarDistanceRead
 * Description:	Function that calculate the Sonar Sensor distance, based on ADC lecture.
 * Parameters:	ADC value.
 * Caveats:		function uses IQ Math  library
 * Return:		Distance *INCHES*
 *****************************************************************************/	
	unsigned char VfnMaxSonarDistanceRead ( unsigned short ADCSonar)
	{
	#if IQ_FORMAT == ON && MAXSONAR_UNITS == MAXSONAR_IN
		return _IQint( _IQmpy(_IQ(ADCSonar),_IQ(MAXSONAR_SENSITIVITY)) );
	#endif
	#if IQ_FORMAT == ON && MAXSONAR_UNITS == MAXSONAR_CM
		return _IQint( _IQmpy(_IQmpy(_IQ(ADCSonar),_IQ(MAXSONAR_SENSITIVITY)),_IQ(2.54)) );
	#endif
	
	#if _IQ_FORMAT == OFF && MAXSONAR_UNITS == MAXSONAR_IN
		// ADCSonar / 2 = 0.5 * ADCSonar
		return (ADCSonar>>1); 
	#endif	
	#if _IQ_FORMAT == OFF && MAXSONAR_UNITS == MAXSONAR_CM
		// ADCSonar / 2 = 0.5 * ADCSonar
		return ((ADCSonar>>1)*2); 
	#endif	
	}
	
#endif

#if MAXSONAR_FORMAT == PWM_DIST
	//function to read distance, counting pulse width.
#endif